class Solution {
public:
    int singleNumber(vector<int>& nums) {
        int f[35] = { 0 };
        int n = nums.size();
        for (auto x : nums) {
            for (int i = 0; i < 32; i++) {
                if (x & (1 << i))f[i]++;
            }
        }
        int ans = 0;
        for (int i = 0; i < 32; i++) {
            if (f[i] % 3 == 1) {
                ans |= (1 << i);
            }
        }
        return ans;
    }
};